package com.yhb.controller;

import com.yhb.controller.vo.ArrayWrapperVo;
import com.yhb.model.Message;
import com.yhb.model.User;
import com.yhb.service.MessageService;
import me.edzh.spring.bootstrap.annotations.CurrentUser;
import me.edzh.spring.bootstrap.annotations.NeedAuth;
import me.edzh.spring.bootstrap.controller.BaseController;
import me.edzh.spring.bootstrap.model.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/message")
public class MessageController extends BaseController {

    @Autowired
    private MessageService messageService;

    @GetMapping("/my/system")
    @NeedAuth
    public Response<ArrayWrapperVo<Message>> getUserSystemMessage(@CurrentUser User user) {
        return Response.ok(new ArrayWrapperVo<>(messageService.userMessages(user.getId(), Message.Type.SYSTEM)));
    }

    @GetMapping("/my/bonus")
    @NeedAuth
    public Response<ArrayWrapperVo<Message>> getUserBonusMessage(@CurrentUser User user) {
        return Response.ok(new ArrayWrapperVo<>(messageService.userMessages(user.getId(), Message.Type.BONUS)));
    }

    @GetMapping("/my/system/first")
    @NeedAuth
    public Response<ArrayWrapperVo<Message>> getUserFirstSystemMessage(@CurrentUser User user) {
        return Response.ok(new ArrayWrapperVo<>(messageService.userFirstMessages(user.getId(), Message.Type.SYSTEM)));
    }

    @GetMapping("/my/bonus/first")
    @NeedAuth
    public Response<ArrayWrapperVo<Message>> getUserFirstBonusMessage(@CurrentUser User user) {
        return Response.ok(new ArrayWrapperVo<>(messageService.userFirstMessages(user.getId(), Message.Type.BONUS)));
    }
}
